
import { Controller, Inject, Get, Query, Post, Put, Body, Del, Param } from '@midwayjs/core';
import { Auth } from "../decorator/auth.decorator";
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@midwayjs/swagger';
import { BusinessType, Log } from "../decorator/log.decorator";
import { TeacherVolunteerTeamService } from '@service/teacherVolunteerTeam.service';
import {
  CreateTeacherVolunteerDto,
  UpdateTeacherVolunteerDto,
  QueryTeacherVolunteerDto,
  DeleteTeacherVolunteerDto,
} from '@dto/teacherVolunteerTeam.dto';

@ApiTags('教师志愿管理')
@Controller('system/teacherVolunteer')
export class TeacherVolunteerTeamController {
  @Inject()
  teacherVolunteerTeamService: TeacherVolunteerTeamService;

  /**
   * 创建/更新教师志愿
   */
  @ApiOperation({ summary: '创建教师志愿', description: '教师在指定分组中选择队伍作为志愿' })
  @ApiBody({ type: CreateTeacherVolunteerDto, description: '教师志愿数据' })
  @ApiResponse({ status: 200, description: '创建成功' })
  @Log({ title: '教师志愿-创建', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() body: CreateTeacherVolunteerDto) {
    return await this.teacherVolunteerTeamService.create(body);
  }

  /**
   * 更新教师志愿
   */
  @ApiOperation({ summary: '更新教师志愿', description: '更新教师在指定分组中的志愿队伍' })
  @ApiBody({ type: UpdateTeacherVolunteerDto, description: '更新的教师志愿数据' })
  @ApiResponse({ status: 200, description: '更新成功' })
  @Log({ title: '教师志愿-更新', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() body: UpdateTeacherVolunteerDto) {
    return await this.teacherVolunteerTeamService.update(body);
  }

  /**
   * 获取教师志愿列表
   */
  @ApiOperation({ summary: '获取教师志愿列表', description: '分页查询教师志愿列表' })
  @ApiResponse({ status: 200, description: '查询成功' })
  @Auth('system:teacherVolunteer:query')
  @Log({ title: '教师志愿-列表', businessType: BusinessType.LIST })
  @Get('/list')
  async list(@Query() query: QueryTeacherVolunteerDto) {
    return await this.teacherVolunteerTeamService.list(query);
  }
  @ApiOperation({ summary: '获取教师所有志愿详情', description: '根据teacherId查询教师志愿详情' })
  @ApiParam({ name: 'teacherId', description: '教师ID' })
  @ApiResponse({ status: 200, description: '查询成功' })
  @Log({ title: '教师志愿-详情', businessType: BusinessType.DETAIL })
  @Get('/:teacherId')
  async getVolunteerDetail(
    @Param('teacherId') teacherId: string
  ) {
    return await this.teacherVolunteerTeamService.getVolunteerDetail(+teacherId);
  }
  /**
   * 获取教师在某个分组的志愿详情
   */
  @ApiOperation({ summary: '获取教师志愿详情', description: '根据groupId和teacherId查询教师志愿详情' })
  @ApiParam({ name: 'groupId', description: '分组ID' })
  @ApiParam({ name: 'teacherId', description: '教师ID' })
  @ApiResponse({ status: 200, description: '查询成功' })
  @Log({ title: '教师志愿-详情', businessType: BusinessType.DETAIL })
  @Get('/:groupId/:teacherId')
  async detail(
    @Param('groupId') groupId: string,
    @Param('teacherId') teacherId: string
  ) {
    return await this.teacherVolunteerTeamService.detail(+groupId, +teacherId);
  }

  /**
   * 删除教师的某些志愿
   */
  @ApiOperation({ summary: '删除教师志愿', description: '删除教师在指定分组中的某些志愿队伍' })
  @ApiBody({ type: DeleteTeacherVolunteerDto, description: '删除的志愿数据' })
  @ApiResponse({ status: 200, description: '删除成功' })
  @Auth('system:teacherVolunteer:remove')
  @Log({ title: '教师志愿-删除', businessType: BusinessType.REMOVE })
  @Del('/')
  async remove(@Body() body: DeleteTeacherVolunteerDto) {
    return await this.teacherVolunteerTeamService.remove(body);
  }

  /**
   * 删除教师在某个分组的所有志愿
   */
  @ApiOperation({ summary: '删除教师所有志愿', description: '删除教师在指定分组中的所有志愿' })
  @ApiParam({ name: 'groupId', description: '分组ID' })
  @ApiParam({ name: 'teacherId', description: '教师ID' })
  @ApiResponse({ status: 200, description: '删除成功' })
  @Auth('system:teacherVolunteer:remove')
  @Log({ title: '教师志愿-删除所有', businessType: BusinessType.REMOVE })
  @Del('/:groupId/:teacherId')
  async removeAll(
    @Param('groupId') groupId: string,
    @Param('teacherId') teacherId: string
  ) {
    return await this.teacherVolunteerTeamService.removeAll(+groupId, +teacherId);
  }
}
